<template>
  <div class="app-container">
    <div class="flex align-center mb10 pb10 border-bottom">
      <div class="text-14 text-bold flex-1">设备变量值列表</div>
    
    </div>
    <el-form class="table-search-view" :model="queryParams" ref="queryForm" size="small" :inline="true"
      v-show="showSearch">
      <!-- <el-form-item prop="deviceName">
        <el-input v-model="queryParams.deviceName" placeholder="请输入设备名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
          <el-form-item prop="deviceName">
            <el-select v-model="queryParams.deviceName" placeholder="请选择设备"> 
              <el-option
                v-for="item in devices"
                :key="item.id"
                :label="item.deviceName"
                :value="item.deviceName">
              </el-option>
            </el-select>
          </el-form-item>
      <!-- <el-select v-model="queryParams.variableType" placeholder="请选择变量类型">
        <el-option v-for="dict in [...[{ label: '全部变量', value: '' }], ...dict.type.variable_type]" :key="dict.value"
          :label="dict.label" :value="dict.value" />
      </el-select> -->
      <el-form-item prop="deviceName">
        <el-input v-model="queryParams.variableName" placeholder="请输入变量名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
       <el-form-item >
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item class="table-search-btn" style="padding-left: 100px">
        <el-button  type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="deviceList" >
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="变量类型" align="center" prop="variableTypeName" />
      <el-table-column label="变量名称" align="center" prop="variableName" />
      <el-table-column label="更新时间" align="center" prop="createTime" >
         <template slot-scope="{row}">
            {{ parseTime(row.createTime) }}
         </template>
      </el-table-column>
      <el-table-column label="变量值" align="center" prop="variableValue" />
      <el-table-column label="单位" align="center" prop="variableUnit" />
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listDevice } from "@/api/iot/device";
import { variableValueHisList } from "@/api/iot/hisdata";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Hisdata",
  components: { Treeselect },
  dicts: ["location_type"],

  data() {
    return {
      supThis: this,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备表格数据
      deviceList: [],
      devices: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceName: null,
        variableName: null,
        variableType: null,
        startDate: null,
        endDate: null,
      },
      // 日期范围
      dateRange: [],
    };
  },
  created() {
    this.getList();
    this.getDeviceList();
  },
  methods: {
    /** 查询设备列表 */
    getList() {
      this.queryParams.startDate = this.dateRange[0];
      this.queryParams.endDate = this.dateRange[1];
      this.loading = true;
      variableValueHisList(this.queryParams).then((response) => {
        this.deviceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
     getDeviceList() {
        listDevice({
          pageNum: 1,
          pageSize: 999
        }).then((response) => {
          this.devices = response.rows;
        });
      },
  },
};
</script>
